package com.chengqj.blogweb.blog.repo.dao;

import com.chengqj.blogweb.blog.repo.pojo.TBlogPhoto;
import java.util.List;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

@Mapper
public interface TBlogPhotoMapper {
    @Delete({
        "delete from t_blog_photo",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into t_blog_photo (type, small_url, ",
        "normal_url, gmt_create, ",
        "is_main)",
        "values (#{type,jdbcType=VARCHAR}, #{smallUrl,jdbcType=VARCHAR}, ",
        "#{normalUrl,jdbcType=VARCHAR}, #{gmtCreate,jdbcType=TIMESTAMP}, ",
        "#{isMain,jdbcType=BIT})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Integer.class)
    int insert(TBlogPhoto record);

    @Select({
        "select",
        "id, type, small_url, normal_url, gmt_create, is_main",
        "from t_blog_photo",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="type", property="type", jdbcType=JdbcType.VARCHAR),
        @Result(column="small_url", property="smallUrl", jdbcType=JdbcType.VARCHAR),
        @Result(column="normal_url", property="normalUrl", jdbcType=JdbcType.VARCHAR),
        @Result(column="gmt_create", property="gmtCreate", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="is_main", property="isMain", jdbcType=JdbcType.BIT)
    })
    TBlogPhoto selectByPrimaryKey(Integer id);

    @Select({
            "select",
            "id, type, small_url, normal_url, gmt_create, is_main",
            "from t_blog_photo",
            "where type = #{type,jdbcType=VARCHAR}"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column="type", property="type", jdbcType=JdbcType.VARCHAR),
            @Result(column="small_url", property="smallUrl", jdbcType=JdbcType.VARCHAR),
            @Result(column="normal_url", property="normalUrl", jdbcType=JdbcType.VARCHAR),
            @Result(column="gmt_create", property="gmtCreate", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="is_main", property="isMain", jdbcType=JdbcType.BIT)
    })
    List<TBlogPhoto> selectByType(String type);

    @Select({
            "select",
            "id, type, small_url, normal_url, gmt_create, is_main",
            "from t_blog_photo",
            "where is_main = true"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column="type", property="type", jdbcType=JdbcType.VARCHAR),
            @Result(column="small_url", property="smallUrl", jdbcType=JdbcType.VARCHAR),
            @Result(column="normal_url", property="normalUrl", jdbcType=JdbcType.VARCHAR),
            @Result(column="gmt_create", property="gmtCreate", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="is_main", property="isMain", jdbcType=JdbcType.BIT)
    })
    List<TBlogPhoto> selectByMain();

    @Select({
        "select",
        "id, type, small_url, normal_url, gmt_create, is_main",
        "from t_blog_photo"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="type", property="type", jdbcType=JdbcType.VARCHAR),
        @Result(column="small_url", property="smallUrl", jdbcType=JdbcType.VARCHAR),
        @Result(column="normal_url", property="normalUrl", jdbcType=JdbcType.VARCHAR),
        @Result(column="gmt_create", property="gmtCreate", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="is_main", property="isMain", jdbcType=JdbcType.BIT)
    })
    List<TBlogPhoto> selectAll();

    @Update({
        "update t_blog_photo",
        "set type = #{type,jdbcType=VARCHAR},",
          "small_url = #{smallUrl,jdbcType=VARCHAR},",
          "normal_url = #{normalUrl,jdbcType=VARCHAR},",
          "gmt_create = #{gmtCreate,jdbcType=TIMESTAMP},",
          "is_main = #{isMain,jdbcType=BIT}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(TBlogPhoto record);
}